<template>
    <LDrawerForm
        :visible="visible"
        :confirmLoading="confirmLoading" 
        :title="title" 
        ref="reportForm" 
        :formAttributes="formAttributes" 
        @handleOk="handleOk" 
        @handleCancel="handleCancel"
        @changeEventHandler="changeEventHandler">
    </LDrawerForm>

</template>

<script>
import LDrawerForm from '@/components/lt/form/LDrawerForm'
import pick from 'lodash.pick'
import request from '@/utils/request'
import defaultSettings from '@/config/defaultSettings'

export default {
    name:'reportForm',
    components:{
        LDrawerForm
    },
    data(){
        return{
            defaultSettings,
            title:'详情',
            visible:false,
            confirmLoading: false,
            model:{},
            formAttributes:{
              type:'',//collapse,tabs
              formItems:[
                {
                  title:'标签一',
                  columns:1,
                  fields:[
                    {field:'reportName',label:'报表名称',component:'input',rules: [{required: true, message: '报表名称不能为空'}]},
                    {field:'reportUrl',label:'报表地址',component:'input',rules: [{required: true, message: '报表 地址不能为空'}]},
                    {field:'reportOrder',label:'排序',component:'inputNumber',rules: [{required: true, message: '排序不能为空'}],initialValue:1},
                    {field:'isUse',label:'是否可用',component:'select',dictCode:defaultSettings.数据字典.是否,rules: [{required: true, message: '是否可用不能为空'}],initialValue:'1'},
                    {field:'systemNo',label:'系统编号',component:'input',disabled:true,initialValue:defaultSettings.systemNo},
                  ]
                },
              ]

            }


        }
    },
    methods:{
       
        edit (record) {
           
            this.visible = true;
            this.model = Object.assign({}, record);

            this.$nextTick(() => {
                this.$refs.reportForm.getForm().setFieldsValue(pick(this.model,'reportName','reportUrl','reportOrder','isUse','systemNo'))
            })
        },
        handleOk(){
            const that = this
            this.$refs.reportForm.getForm().validateFields((err, values) => {
                if (!err) {
                    that.confirmLoading = true
                    let formData = Object.assign(this.model, values);
                    request({url: '/SysRdpReportController/save',method: 'post',data: formData}).then((res)=>{
                        if(res.success){
                            that.close()
                            that.$message.success(res.message);
                        }else{
                            that.$message.warning(res.message);
                        }
                    }).finally(() => {
                        that.confirmLoading = false;
                    })
                    
                }
            })
        },
        handleCancel(){
            this.visible=false
        },
        close () {
            this.$emit('close');
            this.visible = false;
        },
        /**
         * 表单内容发生变化
         */
        changeEventHandler(changeItem){
            console.log(changeItem)
           
        }
    },
    created(){
        
    },
}
</script>